﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BBPA.Admin.Sys.Orders.BuyMoneyFail_Receive
{
    public partial class Form : FormPage
    {
        BLL.Orders bll = new BLL.Orders();
        BLL.V_Orders bllV_Orders = new BLL.V_Orders();
        List<Model.V_Orders> listModelV_Orders = new List<Model.V_Orders>();
        //
        BLL.Orders_Goods bllOrders_Goods = new BLL.Orders_Goods();
        BLL.Goods bllGoods = new BLL.Goods();
        BLL.Supplier bllSupplier = new BLL.Supplier();
        //
        decimal BuyMoneyDiff = 0;
                string BuyMoneyType = "退还";
                
        protected void Page_Load(object sender, EventArgs e) {  }
        /// <summary>
        /// 初始化本页Model
        /// </summary>
        public override void Page_Load_DefaultModel() {  }
        public override void Page_Load_More()
        {
            if (Master.idStr != "")
            {
                listModelV_Orders = bllV_Orders.GetModelList("id in(" + Master.idStr + ")");
                foreach (Model.V_Orders modelV_Orders in listModelV_Orders) BuyMoneyDiff += modelV_Orders.ExpectPay_Delivery - modelV_Orders.ActualPay_Delivery;

                rp_Orders.DataSource = listModelV_Orders;
                rp_Orders.DataBind();
                //
                if (BuyMoneyDiff < 0) BuyMoneyType = "贴补";
                ((Label)rp_Orders.Controls[rp_Orders.Controls.Count - 1].FindControl("lb_BuyMoneyType")).Text = BuyMoneyType;
                ((Label)rp_Orders.Controls[rp_Orders.Controls.Count - 1].FindControl("lb_BuyMoneyDiff")).Text = StringPlus.showMoney(Math.Abs( BuyMoneyDiff));
            }
        }
        /// <summary>
        /// 初始化表单
        /// </summary>
        public override void Form_Default()
        {
        }
        /// <summary>
        /// 绑定表单数据【修改时用】
        /// </summary>
        public override void Form_Bind()
        {
            
        }
        /// <summary>
        /// 提交
        /// </summary>
        public override void Form_Submit()
        {
            foreach (string id in Master.idStr.Split(','))
            {
                int thisID = DataTypePlus.requestInt(id);
                
                //订单
                Model.Orders model = bll.GetModel(thisID);
                model.IsBuyMoneyOK_Delivery = true;
                bll.Update(model);
                BLL.User_Operate_Log.Add(Security.GetCurrentUserID(), EnumHelper.TableName.Orders, thisID, EnumHelper.OperateType.Update, "清算收货款，" + BuyMoneyType + " " + StringPlus.showMoney(Math.Abs(BuyMoneyDiff)));
            }
            Master.SubmitOK("清算收货款成功");
        }
        
    }
}